/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "article")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Article.findAll", query = "SELECT a FROM Article a"),
    @NamedQuery(name = "Article.findByArticleId", query = "SELECT a FROM Article a WHERE a.articleId = :articleId"),
    @NamedQuery(name = "Article.findByArticleIdWithIdRegion", query = "SELECT a FROM Article a WHERE a.regionId.regionId = :regionId"),// all region
    @NamedQuery(name = "Article.findByRegionIdActive", query = "SELECT a FROM Article a WHERE a.regionId.regionId = :regionId AND a.active = :active"),//***
    @NamedQuery(name = "Article.findByArticleIdActive", query = "SELECT a FROM Article a WHERE a.articleId = :articleId AND a.active = :active"),//***
    @NamedQuery(name = "Article.findByTittle", query = "SELECT a FROM Article a WHERE a.tittle = :tittle"),
    @NamedQuery(name = "Article.findByDetailTittle", query = "SELECT a FROM Article a WHERE a.detailTittle = :detailTittle"),
    @NamedQuery(name = "Article.findByImage", query = "SELECT a FROM Article a WHERE a.image = :image"),
    @NamedQuery(name = "Article.findByCreateUserId", query = "SELECT a FROM Article a WHERE a.createUserId = :createUserId"),
    @NamedQuery(name = "Article.findByDeleteUserId", query = "SELECT a FROM Article a WHERE a.deleteUserId = :deleteUserId"),
    @NamedQuery(name = "Article.findByDateCreate", query = "SELECT a FROM Article a WHERE a.dateCreate = :dateCreate"),
    @NamedQuery(name = "Article.ArticleDistinctRegionId", query = "SELECT DISTINCT a.regionId.regionId,a.regionId.name, a.regionId.countryId.name FROM Article a"),// all distinct regionId
    @NamedQuery(name = "Article.ArticleDistinctRegionRegains", query = "SELECT DISTINCT a.regionId.regionId,a.regionId.name, a.regionId.countryId.name FROM Article a WHERE a.regionId.regionId= :regionId "),// all distinct regionId AND Region=dato
    @NamedQuery(name = "Article.findByActive", query = "SELECT a FROM Article a WHERE a.active = :active"),
    @NamedQuery(name = "Article.findByDeleted", query = "SELECT a FROM Article a WHERE a.deleted = :deleted")})
public class Article implements Serializable {
    private static final long serialVersionUID = 1L;
    /*
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "articleId")*/
    @Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer articleId;
    @Basic(optional = false)
    @Column(name = "tittle")
    private String tittle;
    @Column(name = "detailTittle")
    private String detailTittle;
    @Column(name = "image")
    private String image;
    @Column(name = "createUserId")
    private Integer createUserId;
    @Column(name = "deleteUserId")
    private Integer deleteUserId;
    @Column(name = "dateCreate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateCreate;
    @Column(name = "active")
    private Boolean active;
    @Column(name = "deleted")
    private Boolean deleted;
    @OneToMany(mappedBy = "articleId")
    private Collection<Section> sectionCollection;
    @JoinColumn(name = "regionId", referencedColumnName = "regionId")
    @ManyToOne
    private Region regionId;

    public Article() {
    }

    public Article(Integer articleId) {
        this.articleId = articleId;
    }
    //for date bds
    public Article(Integer articleId,Region regionId,String tittle,String detailTittle,String image,Integer createUserId,Integer deleteUserId,Date dateCreate,Boolean active,Boolean deleted) {
    	this.articleId = articleId;
    	this.regionId = regionId;
    	this.tittle = tittle;
    	this.detailTittle = detailTittle;
    	this.image = image;
    	this.createUserId = createUserId;
    	this.deleteUserId = deleteUserId;
    	this.dateCreate = dateCreate;
    	this.active = active;
    	this.deleted = deleted;
    	
    }
    
    
    public Article(Integer articleId, String tittle) {
        this.articleId = articleId;
        this.tittle = tittle;
    }

    public Integer getArticleId() {
        return articleId;
    }

    public void setArticleId(Integer articleId) {
        this.articleId = articleId;
    }

    public String getTittle() {
        return tittle;
    }

    public void setTittle(String tittle) {
        this.tittle = tittle;
    }

    public String getDetailTittle() {
        return detailTittle;
    }

    public void setDetailTittle(String detailTittle) {
        this.detailTittle = detailTittle;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public Integer getCreateUserId() {
        return createUserId;
    }

    public void setCreateUserId(Integer createUserId) {
        this.createUserId = createUserId;
    }

    public Integer getDeleteUserId() {
        return deleteUserId;
    }

    public void setDeleteUserId(Integer deleteUserId) {
        this.deleteUserId = deleteUserId;
    }

    public Date getDateCreate() {
        return dateCreate;
    }

    public void setDateCreate(Date dateCreate) {
        this.dateCreate = dateCreate;
    }

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    @XmlTransient
    public Collection<Section> getSectionCollection() {
        return sectionCollection;
    }

    public void setSectionCollection(Collection<Section> sectionCollection) {
        this.sectionCollection = sectionCollection;
    }

    public Region getRegionId() {
        return regionId;
    }

    public void setRegionId(Region regionId) {
        this.regionId = regionId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (articleId != null ? articleId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Article)) {
            return false;
        }
        Article other = (Article) object;
        if ((this.articleId == null && other.articleId != null) || (this.articleId != null && !this.articleId.equals(other.articleId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Article[ articleId=" + articleId + " ]";
    }
    
}
